package com.liao.work.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.liao.work.R;
import com.liao.work.domain.InfoList;
import com.liao.work.ui.adapter.AdapterInfoListListViewItemAdapter;
import com.liao.work.util.SetActionBarTitle;

import java.util.ArrayList;

public class InfoListActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {

    private ListView listView;

    private ArrayList<InfoList> infoLists;
    private AdapterInfoListListViewItemAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_info_list);
        SetActionBarTitle.setTitle(getSupportActionBar(), false, "信息列表");
        initView();
    }

    private void initView() {
        listView = (ListView) findViewById(R.id.listView);

        infoLists = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            InfoList infoList = new InfoList();
            infoList.setImage(R.mipmap.ok);
            infoList.setText1("aaaa" + i);
            infoList.setText2("bbbbbbbbbbbbbb" + i);
            infoLists.add(infoList);
        }
        adapter = new AdapterInfoListListViewItemAdapter(this, infoLists);
        listView.setAdapter(adapter);

        listView.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Toast.makeText(this, "你点击了：" + infoLists.get(position).getText1(), Toast.LENGTH_SHORT).show();
    }
}
